/******************************************************************************
** @file	ShareTest.cpp
** @author  Andrea Herbas
**
** @date	Jul 22, 2010
**
** @desc	This test must list all the share resources and proove that 
**          the defualt shares(available in any windows version) exist 
**          in the retrieved WMI_Reader result.
*			
**
******************************************************************************/

#include "../Unit--/unit--.h"
#include "../../wmi_share.h"
#include "../../wmi_iwinobject.h"
#include "../../wmi_connection.h"
#include "../../wmi_connectionmanager.h"
#include "../../wmi_result.h"
#include "../../wmi_constants.h"
#include "string"
#include <comdef.h>
#include <Wbemidl.h>

# pragma comment(lib, "wbemuuid.lib")

using namespace unit_minus;

testSuite(WMIReaderSuite);

testCase(ShareTest, WMIReaderSuite)
{
    cout << "---------- Start Share Test ----------" << endl;
    const int sharesNum = 3;
    WMI_Connection con;
	WMI_ConnectionManager* mng = new WMI_ConnectionManager();
	CoUninitialize();
	mng->initCOMSecurityConfiguration();

	mng->createConnection(PC_USER, PC_PASSWORD,PC_IP_REMOTE_HOST,PC_NAMESPACE, con);
	
    WMI_HResult* result = con.executeQuery(L"SELECT * FROM Win32_Share");
    IEnumWbemClassObject* pEnumerator = NULL;
	pEnumerator = con.getIEnumWbemClassObject();
   
    WMI_Result<WMI_Share> res;
	res.fillVector(pEnumerator);

    wstring shareNames[] = {C_SHARE, IPC_SHARE, ADMIN_SHARE};
    int shareCount = 0;

    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < res.getObjects().size(); j++)
        {
            if(shareNames[i] == (res.getObjects()[j])->getName())
            {
                shareCount++;
            }
        }
    }
    res.showObjects();
	con.close();

    assertTrue(shareCount == sharesNum);	
    delete result;
    cout << "---------- End Share Test ----------" << endl << endl;
    system("PAUSE");
}